/*
 * Copyright © 2004-2014 chenYuan. All rights reserved.
 * @Website:wwww.jspx.net
 * @Mail:39793751@qq.com
 * @author: chenYuan , 陈原
 * @License: Jspx.net Framework Code is open source (LGPL)，Jspx.net Framework 使用LGPL 开源授权协议发布。
 * @jvm:jdk1.6+  x86/amd64
 *
 */
package com.jspx.scriptmark.core.dispose;

import com.jspx.scriptmark.Phrase;
import com.jspx.scriptmark.core.TagNode;
import com.jspx.scriptmark.core.EnvRunner;
import com.jspx.scriptmark.core.script.JScriptContext;
import com.jspx.scriptmark.core.block.SettingBlock;
import org.mozilla.javascript.ScriptableObject;

import java.util.List;
import java.io.Writer;
import java.io.StringWriter;


/**
 * Created by IntelliJ IDEA.
 * User: chenYuan
 * Date: 2009-1-2
 * Time: 16:26:07
 *
 */
public class SettingPhrase implements Phrase
{
    public SettingPhrase()
    {

    }
     public int getRun(EnvRunner env, TagNode tagNode, Writer out) throws Exception
     {
            SettingBlock settingBlock = (SettingBlock) tagNode;
            Writer aw = new StringWriter();
            List<TagNode> list = settingBlock.getValueList();
            for (TagNode node : list)
            {
                env.runBlock(node,aw);
            }
            ScriptableObject scripTable = JScriptContext.getInstance().getGlobalScope();
            scripTable.put(settingBlock.getVarName(),scripTable,aw.toString());
            list.clear();
            return 0;
     }
}